<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<h:head>

	<style type="text/css">
.ui-layout-north {
	z-index: 20 !important;
	overflow: visible !important;;
}

.ui-layout-north .ui-layout-unit-content {
	overflow: visible !important;
}

.ui-widget {
	font-size: 10px !important;
}

.size {
	width: 550px;
	position: relative;
	left: 30%;
	top: 10%;
}

.tabela {
	width: 750px;
}
</style>

	<title>Cadastro de Laboratório</title>
</h:head>

<h:body>
	<ui:decorate template="/templateBase.xhtml">

		<ui:define name="center">


			<h:form prependId="false" id="formCadastroLaboratorio">
				<p:hotkey bind="f2" oncomplete="dlg.show()"
					actionListener="#{LaboratorioBacking.carregaLaboratorio}"
					update=":formPesquisa:tabelaLaboratorio" upprocess="@all" />

				<p:hotkey bind="f4" oncomplete="dlgEng.show()"
					actionListener="#{LaboratorioBacking.carregaEngenheiro}"
					update=":formPesquisa:tabelaEngenheiro" upprocess="@all" />

				<br />
				<br />
				<p:panel header="Cadastro de Laboratório" styleClass="size"
					toggleable="true"
					footer="SIGLAS - Sistema de Gerenciamento de Laboratório de Análise de Solos">

					<p:growl id="growl" life="3000" autoUpdate="true" />
					<br />
					<p:tabView>
						<p:tab title="Dados do Laboratório">
							<h:panelGrid columns="3">

								<h:outputText value="Nome do Laboratório: " />
								<p:inputText size="45" maxlength="45"
									value="#{LaboratorioBacking.laboratorioSalvar.descricao}" />
								<p:commandButton value="F2" icon="ui-icon-search"
									oncomplete="dlg.show()"
									actionListener="#{LaboratorioBacking.carregaLaboratorio}"
									update=":formPesquisa:tabelaLaboratorio" upprocess="@all" />

								<h:outputText value="Engenheiro Responsável: " />
								<p:inputText size="45" disabled="true"
									value="#{LaboratorioBacking.engenheiroSelecionado.pessoa.nome}" />

								<p:commandButton value="F4" icon="ui-icon-search"
									oncomplete="dlgEng.show()"
									actionListener="#{LaboratorioBacking.carregaEngenheiro}"
									update=":formPesquisa:tabelaEngenheiro" upprocess="@all" />

							</h:panelGrid>

						</p:tab>

						<!-- ABA ENDEREÇO -->
						<p:tab title="Endereço" effect="fade" effectDuration="fast">

							<h:panelGrid columns="4">

								<h:outputText value="Logradouro:(*)" />
								<p:inputText size="52"
									value="#{LaboratorioBacking.enderecoSalvar.logadouro}" />

								<h:outputText value="Nº:" />
								<p:inputMask size="5" mask="?99999"
									value="#{LaboratorioBacking.enderecoSalvar.numero}" />

							</h:panelGrid>
							<h:panelGrid columns="2">
								<h:outputText value="Complemento:" />
								<p:inputText size="50"
									value="#{LaboratorioBacking.enderecoSalvar.complemento}" />

								<h:outputText value="Estado:(*)" />
								<p:selectOneMenu effect="drop" id="estado"
									value="#{LaboratorioBacking.estadoSalvar}">
									<p:ajax listener="#{LaboratorioBacking.carregarCidades}"
										update="cidade" process="@all" />
									<f:selectItem itemLabel="Selecione um Estado" />
									<f:selectItems value="#{LaboratorioBacking.listaEstados}"
										var="e" itemValue="#{e.codigo}"
										itemLabel="#{e.nome} - #{e.sigla}" />

								</p:selectOneMenu>

								<h:outputText value="Cidade:(*)" />

								<p:selectOneMenu effect="drop" id="cidade"
									value="#{LaboratorioBacking.cidadeSalvar}">
									<f:selectItem itemLabel="Selecione uma Cidade" />
									<f:selectItems value="#{LaboratorioBacking.listaCidades}"
										var="c" itemLabel="#{c.nome}" itemValue="#{c.codigo}" />

								</p:selectOneMenu>

								<h:outputText value="Bairro:" />
								<p:inputText value="#{LaboratorioBacking.enderecoSalvar.bairro}" />

								<h:outputText value="CEP:" />
								<p:inputMask mask="99.999-999"
									value="#{LaboratorioBacking.enderecoSalvar.cep}" />
								<br />
							</h:panelGrid>
						</p:tab>
						<!-- CONFIGURACOES DE MIDIA -->
						<p:tab title="Configurações de Mídia">
							<h2>Configurações de E-mail:</h2>
							<h:panelGrid columns="2">

								<h:outputText value="HostName:" />
								<p:inputText value="#{LaboratorioBacking.configuracao.nameHost}"
									maxlength="45" label="Ex: smtp.gmail.com" size="45" />

								<h:outputText value="E-mail:" />
								<p:inputText value="#{LaboratorioBacking.configuracao.email}"
									maxlength="45" size="45" />

								<h:outputText value="Usuário:" />
								<p:inputText value="#{LaboratorioBacking.configuracao.usuario}"
									maxlength="45" size="20" />

								<h:outputText value="Senha" />
								<p:password value="#{LaboratorioBacking.configuracao.senha}"
									redisplay="true" maxlength="45" size="20" />

								<h:outputText value="SMTP Port:" />
								<p:inputMask mask="?99999"
									value="#{LaboratorioBacking.configuracao.smtpPorta}"
									maxlength="5" size="5" />

								<h:outputText value="SSL:" />
								<p:selectOneRadio id="ssl" immediate="true"
									value="#{LaboratorioBacking.configuracao.certificadoSsl}">
									<f:selectItem itemLabel="True" itemValue="true" />
									<f:selectItem itemLabel="False" itemValue="false" />
								</p:selectOneRadio>

								<h:outputText value="TLS:" />
								<p:selectOneRadio id="tls" immediate="true"
									value="#{LaboratorioBacking.configuracao.certificadoTls}">
									<f:selectItem itemLabel="True" itemValue="true" />
									<f:selectItem itemLabel="False" itemValue="false" />
								</p:selectOneRadio>
							</h:panelGrid>
							<hr />

						</p:tab>
					</p:tabView>
					<br />
					<div align="center">
						<h:panelGrid columns="4">
							<p:commandButton value="Salvar"
								actionListener="#{LaboratorioBacking.salvar}" update="growl" />
							<p:commandButton value="Excluir"
								actionListener="#{LaboratorioBacking.delete}" />
							<p:commandButton value="Cancelar" />
						</h:panelGrid>
					</div>

				</p:panel>
			</h:form>
			<!-- PESQUISA DE LABORATÓRIOS -->
			<h:form id="formPesquisa">
				<p:dialog id="pesquisaLaboratorio" widgetVar="dlg"
					header="Pesquisar Laboratório" closable="true" resizable="false"
					showEffect="clip" hideEffect="clip">

					<p:dataTable id="tabelaLaboratorio" var="lab"
						value="#{LaboratorioBacking.listaLaboratorio}" paginator="true"
						rows="5">
						<f:facet name="header">
							<h:outputText value="Laboratórios Cadastradas" />
						</f:facet>

						<p:column headerText="Código">
							<h:outputText value="#{lab.getcodigoFormatado()}" />
						</p:column>

						<p:column headerText="Descrição">
							<h:outputText value="#{lab.descricao}" />
						</p:column>
						<p:column headerText="Engenheiro Reponsável">
							<h:outputText value="#{lab.engenheiro}" />
						</p:column>
						<p:column headerText="Ações">
							<div align="center">
								<h:panelGrid columns="2">
									<p:commandButton icon="ui-icon-pencil" onclick="dlg.hide()"
										ajax="false" action="#{LaboratorioBacking.preparaAlteracao}">
										<f:setPropertyActionListener
											target="#{LaboratorioBacking.laboratorioSelecionado}"
											value="#{lab}" />
									</p:commandButton>

									<p:commandButton icon="ui-icon-close"
										onclick="dlgDelete.show()">
										<f:setPropertyActionListener
											target="#{LaboratorioBacking.laboratorioSelecionado}"
											value="#{lab}" />
									</p:commandButton>

								</h:panelGrid>
							</div>
						</p:column>

					</p:dataTable>
				</p:dialog>
				<!-- PESQUISA DE ENGENHEIRO -->
				<p:dialog id="pesquisaEngenheiro" widgetVar="dlgEng"
					header="Pesquisar Engenheiro" closable="true" resizable="false"
					showEffect="clip" hideEffect="clip" >

					<p:dataTable id="tabelaEngenheiro" var="eng" selectionMode="single"
						value="#{LaboratorioBacking.listaEngenheiro}" paginator="true"
						rows="5" selection="#{LaboratorioBacking.engenheiroSelecionado}"
						rowKey="#{eng.codigo}" emptyMessage="Nenhum Engenheiro foi Encontrado, verifique o cadastro de Funcionários.">

						<p:ajax event="rowSelect" update=":formCadastroLaboratorio"
							onstart="dlgEng.hide()" />

						<f:facet name="header">
							<h:outputText value="Engenehiros Cadastrados" />
						</f:facet>

						<p:column headerText="Nome Engenheiro">
							<h:outputText value="#{eng.pessoa.nome}" />
						</p:column>

						<p:column headerText="Cargo">
							<h:outputText value="#{eng.cargo.descricao}" />
						</p:column>


					</p:dataTable>
				</p:dialog>
				<p:dialog id="confirmaDelete" widgetVar="dlgDelete"
					header="Deletar Registro" closable="true" width="230"
					resizable="false" showEffect="clip" hideEffect="clip">
					<div align="center">
						<h:outputText value="Deseja realmente excluir esse registro?" />
						<h:panelGrid columns="2">
							<p:commandButton value="Sim" onsuccess="dlgDelete.hide()"
								actionListener="#{LaboratorioBacking.delete}"
								update=":formPesquisa:pesquisaLaboratorio, :formCadastroLaboratorio"
								process="@all" immediate="true" />
							<p:commandButton value="Não" onclick="dlgDelete.hide()" />
						</h:panelGrid>
					</div>
				</p:dialog>
			</h:form>

		</ui:define>
	</ui:decorate>
</h:body>
</html>
